<?php include "templates/header.php";
if(isset($_POST['add_news'])){
    unset($_POST['add_news']);
    $_POST['show'] = $_POST['show'] ? 1 : 0;
    foreach ($_POST as $key => $value) {
        $news[$key] = $value;
    }
    $news['date'] = date("Y-m-d H:i:s");
    mysql_insert('news', $news);
}
$news_array = mysql_select_array("SELECT * FROM `news` ORDER BY `id` DESC");
?>
Добавить новость
<form action="" method="post">
    <input type="hidden" name="add_news" value="1" />
    <table>
        <tr>
            <td style="text-align: right;">Заголовок</td>
            <td style="width: 10px; text-align: center;">:</td>
            <td><input type="text" name="title" /></td>
        </tr>
        <tr>
            <td style="text-align: right;">Ссылка на новость</td>
            <td style="width: 10px; text-align: center;">:</td>
            <td><input type="text" name="link" /></td>
        </tr>
        <tr>
            <td style="text-align: right;">Ссылка на изображение</td>
            <td style="width: 10px; text-align: center;">:</td>
            <td><input type="text" name="img" /></td>
        </tr>
        <tr>
            <td style="text-align: right;">Показывать на сайте</td>
            <td style="width: 10px; text-align: center;">:</td>
            <td><input type="checkbox" name="show" value="1" /></td>
        </tr>
        <tr>
            <td style="text-align: right;">&nbsp;</td>
            <td style="width: 10px; text-align: center;">&nbsp;</td>
            <td><input type="submit" value="Добавить" /></td>
        </tr>
    </table>
</form>
<ul style="list-style: none;">
    <?foreach($news_array as $news):?>
        <li><input type="checkbox" onclick="change_news_status('<?=$news['id'];?>');" <?if($news['show']):?>checked="checked"<?endif?> /><?=$news['title'];?></li>
    <?endforeach;?>
</ul>
<script>
function change_news_status(id){
    $.post("<?=BASE_URL;?>source/ajax.php?action=change_news_status", {id: id});
}
</script>
<?php include ROOT_PATH . "admin/templates/footer.php"; ?>